package Watcher.impl;

import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Exporter {
	public static <T> void write(String path, T object) throws IOException {
		ObjectOutputStream objectOutputStream = new ObjectOutputStream(
				new BufferedOutputStream(new FileOutputStream(path)));

		objectOutputStream.writeObject(object);
		objectOutputStream.close();
	}

	@SuppressWarnings("unchecked")
	public static <T> T read(String path) throws FileNotFoundException,
			IOException, ClassNotFoundException {
		ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path));
		return (T) ois.readObject();
	}
}
